//
//  LWComposeView.swift
//  Swift_Weibo_HLW
//
//  Created by huanglinwang on 16/9/27.
//  Copyright © 2016年 Linwang. All rights reserved.
//

import UIKit
    //  撰写视图罩层
class LWComposeView: UIView {
    
    
    //  MARK: --    懒加载控件
    private lazy var sloganImageView: UIImageView = UIImageView(image: UIImage(named: "compose_slogan"))

    
        override init(frame: CGRect) {
            super.init(frame: frame)
            self.size = CGSize(width: ScreenWidth, height: UIScreen.main.bounds.size.height)
            setupUI()
        }
        
        required init?(coder aDecoder: NSCoder) {
            fatalError("init(coder:) has not been implemented")
        }
        
        private func setupUI() {
            backgroundColor = RandomColor()
            //  获取模糊效果图片
            let image = UIImage.screenShot().applyLightEffect()

            let bgImageView = UIImageView(image: image)
            addSubview(bgImageView)
            addSubview(sloganImageView)

            
            sloganImageView.snp_makeConstraints { (make) in
                make.top.equalTo(self).offset(100)
                make.centerX.equalTo(self)
            }

            
            let button = LWComposeButton()
            button.size = CGSize(width: 80, height: 110)
            button.setImage(UIImage(named: "tabbar_compose_idea"), for: .normal)
            button.setTitle("文字", for: .normal)
            
            
            addChildButton()

        }
    

//  添加子按钮
private func addChildButton() {
    //  按钮的宽度
    let buttonWidth: CGFloat = 80
    //  按钮的高度
    let buttonHeight: CGFloat = 110
    //  按钮的间距
    let buttonMargin: CGFloat = (width - 3 * buttonWidth) / 4
    
    for i in 0..<6 {
        //  列的索引
        let colIndex = i % 3
        //  行的索引
        let rowIndex = i / 3
        
        
        let button = LWComposeButton()
        button.x = CGFloat(colIndex) * buttonWidth + CGFloat(colIndex + 1) * buttonMargin
        button.y = CGFloat(rowIndex) * buttonHeight + CGFloat(rowIndex) * buttonMargin
        
        button.size = CGSize(width: buttonWidth, height: buttonHeight)
        button.setImage(UIImage(named: "tabbar_compose_idea"), for: .normal)
        button.setTitle("文字", for: .normal)
        
        addSubview(button)
    }

}
    
    

        override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
            removeFromSuperview()
        }
    

}

